<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width initial-scale=1 user-scalable=no"/>
    <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="https://imgcache.qq.com/qcloud/cloudbase-js-sdk/1.6.0/cloudbase.full.js"></script>
    <script src="../cloudbase/cloudbase-login.js"></script>
    <script src="../cloudbase/cloudbase-api.js"></script>
    <script src="../jcui/jcui.js"></script>
    <link rel="stylesheet" href="../js/bootstrap-4.5.3-dist/css/bootstrap.css">
    <script src="../js/bootstrap-4.5.3-dist/js/bootstrap.bundle.js"></script>
    <title>登录</title>
    <style>
        html{
            width:100%;height: 100%;
        }
        body{
            width:100%;
            height: 100%;
            display: flex;
            align-items: center;
            align-content: center;
            justify-items: center;
            justify-content: center;
        }
        label{
            color:rgba(0,0,0,0.5);
        }
        section{

        }
    </style>
</head>
<body class="p-2">

    <section class="container-sm p-2 rounded">
        <h2 class="h3 text-center font-weight-bolder">登录</h2>
        <h5 class="h5 text-center text-secondary">诗歌本</h5>
        <div>
            <div class="form-group">
                <label for="email">邮箱</label>
                <input type="email" class="form-control" id="email" autocomplete="on">
            </div>
            <div class="form-group">
                <label for="pwd">密码</label>
                <input type="password" class="form-control" id="pwd" autocomplete="off">
            </div>
            <div class="form-check clearfix">
                    <a href="./zhuze.html" class="float-right mr-2">注册</a>
                    <a href="./resetPassWord.html" class="float-right mr-2">忘记密码？</a>
            </div>
            <button type="button" class="btn btn-primary" onclick="submit()">登录</button>
        </div>
    </section>

</body>
</html>
<script>


    init()
    async function init(){
        await anonymouslogin()
    }
    async function submit(){
        const email = $('#email').val()
        const pwd = $('#pwd').val()
        let res
        if(email==''){
            alert('请填写邮箱地址')
            return
        }
        if(pwd==''){
            alert('请填写密码')
            return
        }
        try{
            res = await loginEmail(email,pwd)
            if(getQueryRedirect()){
                window.location.href = loginHtmlPath[getQueryRedirect()]
            }else{
                window.location.href = INDEXHTML
            }

        }catch(e) {
            const err = e.message
            let errmsg = JSON.parse(err)
            confirm('错误代码：'+errmsg.msg+'\n登录失败，请检查邮箱或密码填写是否正确')
        }
    }
    //检查当前是否传入重定向页面
    function getQueryRedirect(){
        let query = getcanshu()
        if(query['redirect']){
            return query['redirect']
        }
        return false
    }

</script>

